//
//	HOME AUTOMATION GATEWAY PROJECT
//
//  (c) 2008 mocom software GmbH & Co KG
//	for European Microsoft Innovation Center
//
//  $Author: volker $
//  $Date: 2009-03-27 16:38:14 +0100 (Fr, 27. Mrz 2009) $
//  $Revision: 302 $
//
//  Microsoft dotNetMF Project
//  Copyright ©2001,2002,2003,2004 Microsoft Corporation
//  One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
//  All rights reserved.
//  MICROSOFT CONFIDENTIAL
//
//-----------------------------------------------------------------------------

#include <tinyhal.h>
#include "..\STNAND0x.h"
#include <Drivers\BlockStorage\WearLeveling\BS_WearLeveling.h>


//--//

#define STNAND0x__SIZE_IN_BYTES                  FLASH_BLOCK_SIZE*FLASH_BLKS_1GBIT
#define STNAND0x__WP_GPIO_PIN                    GPIO_PIN_NONE
#define STNAND0x__WP_ACTIVE                      FALSE


// BlockDeviceInformation
#define STNAND0x__IS_REMOVABLE                   FALSE
#define STNAND0x__SUPPORTS_XIP                   FALSE
#define STNAND0x__WRITE_PROTECTED                FALSE
#define STNAND0x__NUM_REGIONS                    1

//--//
#ifdef MEMORY_USAGE_SPECIAL
#undef MEMORY_USAGE_SPECIAL
#endif

#ifdef MEMORY_USAGE_SPECIAL2
#undef MEMORY_USAGE_SPECIAL2
#endif

#ifdef MEMORY_USAGE_SPECIAL3
#undef MEMORY_USAGE_SPECIAL3
#endif

//--//

const BlockRange s_STNAND0x_BlockRange[] =
{
 /*   { BlockRange::BLOCKTYPE_BOOTSTRAP ,  0,  1 },
    { BlockRange::BLOCKTYPE_CODE      ,  2, 31 },*/

    { BlockRange::BLOCKTYPE_DEPLOYMENT, 32-FLASH_START_BLOCK, 39-FLASH_START_BLOCK },
    { BlockRange::BLOCKTYPE_DEPLOYMENT, 40-FLASH_START_BLOCK, 47-FLASH_START_BLOCK },
    { BlockRange::BLOCKTYPE_DEPLOYMENT, 48-FLASH_START_BLOCK, 55-FLASH_START_BLOCK },
    { BlockRange::BLOCKTYPE_DEPLOYMENT, 56-FLASH_START_BLOCK, 63-FLASH_START_BLOCK },
    
	{ BlockRange::BLOCKTYPE_STORAGE_A , 64-FLASH_START_BLOCK, 64-FLASH_START_BLOCK },
    { BlockRange::BLOCKTYPE_STORAGE_B , 65-FLASH_START_BLOCK, 65-FLASH_START_BLOCK },
    
	{ BlockRange::BLOCKTYPE_CONFIG    , 66-FLASH_START_BLOCK, 66-FLASH_START_BLOCK },
    
    { BlockRange::BLOCKTYPE_FILESYSTEM, 67-FLASH_START_BLOCK, FLASH_BLKS_1GBIT - 1 }
};

static struct BlockRegionInfo g_STNAND0x_BlkRegion[1] =
{
    FLASH_BASE_ADDRESS_ADJUSTED,	// ByteAddress  Start; ,Starting Sector address
    FLASH_BLKS_1GBIT,               // UINT32       NumBlocks; ,total number of blocks in this region
    FLASH_BLOCK_SIZE,               // UINT32       BytesPerBlock; ,Total number of bytes per block (MUST be SectorsPerBlock * DataBytesPerSector)

    ARRAYSIZE_CONST_EXPR(s_STNAND0x_BlockRange),
    s_STNAND0x_BlockRange, 
};

//--//

static struct BlockDeviceInfo s_STNAND0x_DeviceInfo;
static struct BLOCK_CONFIG s_STNAND0x_BS_Config;

//--//
#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rwdata = "g_STNAND0x_BS_WL"
#endif

extern struct IBlockStorageDevice g_STNAND0x_BS_DeviceTable;
struct BS_WearLeveling_Config g_STNAND0x_BS_WearLeveling_Config;

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rwdata
#endif


BLOCK_CONFIG *STNAND0x_BL_InitConfig(int withwl)
{
	s_STNAND0x_DeviceInfo.Attribute.Removable 			= STNAND0x__IS_REMOVABLE;
	s_STNAND0x_DeviceInfo.Attribute.SupportsXIP 		= STNAND0x__SUPPORTS_XIP;
	s_STNAND0x_DeviceInfo.Attribute.WriteProtected 		= STNAND0x__WRITE_PROTECTED;
	
	s_STNAND0x_DeviceInfo.MaxSectorWrite_uSec		 	= FLASH_SECTOR_WRITE_MAX_TIME_USEC;
	s_STNAND0x_DeviceInfo.MaxBlockErase_uSec 			= FLASH_BLOCK_ERASE_MAX_TIME_USEC;
	
	s_STNAND0x_DeviceInfo.NumRegions 					= ARRAYSIZE_CONST_EXPR(g_STNAND0x_BlkRegion);
	s_STNAND0x_DeviceInfo.Regions						= g_STNAND0x_BlkRegion;
	s_STNAND0x_DeviceInfo.Size							= STNAND0x__SIZE_IN_BYTES;
	s_STNAND0x_DeviceInfo.BytesPerSector				= FLASH_SECTOR_SIZE;

	s_STNAND0x_BS_Config.WriteProtectionPin.Pin 		= STNAND0x__WP_GPIO_PIN;
	s_STNAND0x_BS_Config.WriteProtectionPin.ActiveState = STNAND0x__WP_ACTIVE;
	s_STNAND0x_BS_Config.BlockDeviceInformation 		= &s_STNAND0x_DeviceInfo;	
	
	if (withwl) {
		g_STNAND0x_BS_WearLeveling_Config.BlockConfig 	= &s_STNAND0x_BS_Config;
		g_STNAND0x_BS_WearLeveling_Config.Device 		= &g_STNAND0x_BS_DeviceTable;
		g_STNAND0x_BS_WearLeveling_Config.BlockIndexMask= 0;
		g_STNAND0x_BS_WearLeveling_Config.BytesPerBlock = FLASH_BLOCK_SIZE;
		g_STNAND0x_BS_WearLeveling_Config.BadBlockList 	= NULL;	
		
		return (BLOCK_CONFIG *) &g_STNAND0x_BS_WearLeveling_Config;
	}

	return &s_STNAND0x_BS_Config;
}


#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata = "g_STNAND0x_BS"
#endif

struct BlockStorageDevice g_STNAND0x_BS;

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata
#endif

//--//

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata = "g_STNAND0x_BS_Driver"
#endif

struct STNAND0x_BS_Driver g_STNAND0x_BS_Driver;

#if defined(ADS_LINKER_BUG__NOT_ALL_UNUSED_VARIABLES_ARE_REMOVED)
#pragma arm section rodata
#endif

//--//

